﻿using System;
using System.Data;
using System.Collections.Generic;

using System.Text;
using TimKen.DataEntity;

namespace TimKen.BussLogic
{
    /// <summary>
    /// 配送方式业务逻辑操作类
    /// </summary>
    public class TransTypeManager : BaseManager
    {
        private readonly TimKen.DataAccess.TransTypeDAO dal = new TimKen.DataAccess.TransTypeDAO();
        public TransTypeManager()
        { }
        #region  成员方法
        /// <summary>
        /// 是否存在该记录
        /// </summary>
        public bool Exists(int TransTypeID, int LanguageID)
        {
            return dal.Exists(TransTypeID, LanguageID);
        }


        public bool Exists(params TransType[] modelList)
        {
            long TransTypeCount = this.GetListCount(" (TransTypeName='" + modelList[0].TransTypeName + "' or TransTypeName='" + modelList[1].TransTypeName + "') and TransTypeID<>" + modelList[0].TransTypeID);
            if (TransTypeCount == 0)
                return false;
            else
                return true;
        }

        public bool Exists(TimKen.DataEntity.TransType model)
        {
            long CategoryCount = this.GetListCount(" TransTypeName='" + model.TransTypeName + "' and TransTypeID<>" + model.TransTypeID);
            if (CategoryCount == 0)
                return false;
            else
                return true;
        }

        /// <summary>
        /// 得到最大ID
        /// </summary>
        public int GetMaxId()
        {
            return dal.GetMaxId();
        }

        /// <summary>
        /// 增加一条数据
        /// </summary>
        public bool Add(TimKen.DataEntity.TransType model)
        {
            ValidMessage = "";
            bool isExists = Exists(model);
            if (isExists)
            {
                ValidMessage = GetLangString("ExistTransType"); ;
                return false;
            }
            else
            {
                dal.Add(model);
                ValidMessage = GetLangString("SaveSuccessful");
                return true;
            }
        }

        public int Add(params TransType[] modelList)
        {
            ValidMessage = "";
            int newid = GetMaxId(); bool isExists = Exists(modelList);
            if (isExists)
            {
                ValidMessage = GetLangString("ExistTransType"); ;
                return -1;
            }
            else
            {
                foreach (TransType transType in modelList)
                {
                    transType.TransTypeID = newid;
                    dal.Add(transType);
                }
                ValidMessage = GetLangString("SaveSuccessful");
                return newid;
            }
        }


        /// <summary>
        /// 更新一条数据
        /// </summary>
        public bool Update(TimKen.DataEntity.TransType model)
        {
            if (Exists(model))
            {
                ValidMessage = GetLangString("ExistTransType");
                return false;
            }
            else
            {
                dal.Update(model);
                ValidMessage = GetLangString("SaveSuccessful");
                return true;
            }
        }

        public bool Update(params TransType[] modelList)
        {
            ValidMessage = "";
            if (Exists(modelList))
            {
                ValidMessage = GetLangString("ExistTransType");
                return false;
            }
            else
            {
                dal.Update(modelList[0]);
                dal.Update(modelList[1]);
                ValidMessage = GetLangString("SaveSuccessful");
                return true;
            }
        }

        /// <summary>
        /// 删除一条数据
        /// </summary>
        /*
        public void Delete(int TransTypeID, int LanguageID)
        {

            dal.Delete(TransTypeID, LanguageID);
        }
        */
        public void Delete(int TransTypeID)
        {
            dal.Delete(TransTypeID);
        }


        /// <summary>
        /// 得到一个对象实体
        /// </summary>
        public TimKen.DataEntity.TransType GetModel(int TransTypeID, int LanguageID)
        {

            return dal.GetModel(TransTypeID, LanguageID);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetList(string strWhere)
        {
            return dal.GetList(strWhere);
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        public DataSet GetAllList()
        {
            return GetList("");
        }

        /// <summary>
        /// 获得数据列表
        /// </summary>
        //public DataSet GetList(int PageSize,int PageIndex,string strWhere)
        //{
        //return dal.GetList(PageSize,PageIndex,strWhere);
        //}

        /// <summary>
        /// 获取符合条件的数量
        /// </summary>
        /// <param name="strWhere"></param>
        /// <returns></returns>
        public long GetListCount(string strWhere)
        {
            return dal.GetListCount(strWhere);
        }

        #endregion  成员方法
    }
}

